import java.util.ArrayList;
import java.util.Scanner;

public class KaraokeSystem {
    private ArrayList<String> songs = new ArrayList<>();
    private Scanner scanner = new Scanner(System.in);

    public void run() {
        while (true) {
            System.out.println("1.========== 添加歌曲==========");
            System.out.println("2.========== 将歌曲置顶==========");
            System.out.println("3.========== 将歌曲前移一位==========");
            System.out.println("4.============ 退出=============");
            System.out.println("5.========== 查看歌单列表============");
            System.out.print("===========请输入选项：=======");
            String command = scanner.nextLine();

            switch (command) {
                case "1":
                    addSong();
                    break;
                case "2":
                    moveSongToTop();
                    break;
                case "3":
                    moveSongUp();
                    break;
                case "4":
                    System.out.println("退出系统。");
                    return;
                case "5":
                    printSongList();
                    break;
                default:
                    System.out.println("无效指令，请重新输入！");
                    break;
            }
        }
    }

    private void addSong() {
        System.out.print("输入歌曲名：");
        String songName = scanner.nextLine();
        songs.add(songName);
        System.out.println("歌曲添加成功！");
    }

    private void moveSongToTop() {
        System.out.print("输入要置顶的歌曲名：");
        String songName = scanner.nextLine();
        if (songs.remove(songName)) {
            songs.add(0, songName);
            System.out.println("歌曲已置顶！");
        } else {
            System.out.println("歌曲不存在！");
        }
    }

    private void moveSongUp() {
        System.out.print("输入要提前的歌曲名：");
        String songName = scanner.nextLine();
        int index = songs.indexOf(songName);
        if (index > 0) {
            songs.remove(index);
            songs.add(index - 1, songName);
            System.out.println("歌曲已提前一位！");
        } else {
            System.out.println("歌曲不存在或已在最前！");
        }
    }

    private void printSongList() {
        System.out.println("当前歌单列表：" + songs);
    }

    public static void main(String[] args) {
        KaraokeSystem system = new KaraokeSystem();
        system.run();
    }
}